<template>
  <div>
    <div class="wrapper">
      <div class="line">
        <FormPanel ref="form" :list="formList" :cols="3" :formType="type" :isSubmitBtn="false" />
        <BreakSpace label="台账" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
        <FilterTable
          ref="table"
          columnsRef="jzyContactsPanel"
          height="800"
          :columns="columns"
          :fetchapi="fetchApi"
          :params="fetchParams"
          :datakey="'rows'"
          selectionType="single"
          :onRowSelectChange="rowSelectHandle"
          :onColumnsChange="columns => (this.columns = columns)"
        >
          <template slot="moreActions">
            <span @click="removeRecordHandle">删除数据</span>
          </template>
        </FilterTable>
        <div
          :style="{
            position: 'absolute',
            left: 0,
            bottom: 0,
            right: 0,
            zIndex: 9,
            borderTop: '1px solid #e9e9e9',
            padding: '10px 20px',
            background: '#fff',
            textAlign: 'right'
          }"
        >
          <el-button @click="closeHandler">关闭</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  // @author:@刘诗文
  import { dictionary } from '@/utils/dictMixin';
  import { authority } from '@/utils/authMixin';
  import { notifyAction, confirmAction } from '@/utils';
  import { phone, telePhone } from '@/utils/validate';
  import { getLedger } from '@/api/repair/queryStatistics/queryAccounts';
  import { getUserListSelect } from '@/api/report/repair/repairreport';
  import dictCode from '@/utils/dictCode';
  import { searchRoleByCode } from '@/api/common/empSelect/index';

  export default {
    name: 'contactsPanel',
    components: {},
    mixins: [dictionary, authority],
    props: {
      formData: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      this.selectedRow = null;
      return {
        formList: this.createFormList(),
        columns: this.createTableColumns(),
        fetchApi: getLedger,
        fetchParams: { TIME: this.formData[0],TIME2: this.formData[1] }
      };
    },
    mounted() {
      this.initSelect();
    },
    created() {
      this.init();
    },
    methods: {
      async initSelect() {
        
        let testDrive = { role: dictCode.SERVICE_CONSULTANT };
        let res5 = (await searchRoleByCode(testDrive)).data.map(x => ({ value: x.userId + '', text: x.employeeName }));  
        this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems =  res5;
     },
      createTableColumns() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '委托书编号',
            dataIndex: 'RO_NO',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '牌照号',
            dataIndex: 'LICENSE',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '车型名称',
            dataIndex: 'MODEL',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '客户名称',
            dataIndex: 'OWNER_NAME',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '客户地址',
            dataIndex: 'ADDRESS',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '主要报修项目',
            dataIndex: 'LABOUR_NAME',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '底盘号',
            dataIndex: 'VIN',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '发动机号',
            dataIndex: 'ENGINE_NO',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '送修日期',
            dataIndex: 'RO_CREATE_DATE',
            width: 150,
            dateFormat: 'yyyy-MM-dd',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'date-range',
            editable: false,
            editType: 'date-picker'
          },
          {
            title: '联系人姓名',
            dataIndex: 'CONTACTOR_NAME',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '服务顾问',
            dataIndex: 'SERVICE_ADVISOR',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            editType: 'select',
            editItems:[]
          },

          {
            title: '审核日期',
            dataIndex: 'SHRQ',
            width: 150,
            dateFormat: 'yyyy-MM-dd',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'date-range',
            editable: false,
            editType: 'date-picker'
          }
        ];
      },
      createFormList() {
        return [

        ];
      },

      init(){

        this.formList.find(x=>x.fieldName==='startTime|stopTime').initialValue =this.formData;
        this.getParams();
      },
      async getParams(){
        let res = await getLedger(this.formData);
        console.log(res,'台账');
        this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(res.data.rows);
      },
      rowSelectHandle(rows) {
        if (!rows.length) {
          this.selectedRow = null;
        } else {
          this.selectedRow = rows[0];
        }
      },
      async removeRecordHandle() {

      },
      async saveHandler() {

      },
      // 主页面刷新
      refreshHandle() {
        this.fetchParams = { ...this.fetchParams };
      },
      // 关闭面板
      closeHandler(type) {
        this.$emit('close', false, type);
      }
    }
  };
</script>

<style lang="less" scoped></style>

